package com.msite.util
import com.github.pagehelper.PageHelper
import com.github.pagehelper.PageInfo
import com.msite.framework.PageResult

/**
 * Created by tpeng on 2015/12/14.
 */
class PageHelperUtil {

    static PageInfo startPage(Integer page = 1, Integer pernum = 10, Closure<List> closure) {
        def pageInfo = null
        if (page && pernum) {
            PageHelper.startPage(page, pernum)
            pageInfo = new PageInfo(closure.call())
        }
        pageInfo
    }

    static PageResult startPageResult(Integer page = 1, Integer pernum = 10, Closure<List> closure) {
        def info = startPage(page, pernum, closure)
        convertPageResult(info)
    }

    static PageResult convertPageResult(PageInfo pinfo){
        new PageResult(pinfo.pageNum, pinfo.total as int, pinfo.list)
    }
}
